package dao

import (
	"context"
	"device-admin/internal/dal"
	"device-admin/internal/models"
)

type Floor struct{}

// FloorNameMap 获取FloorID 对应的名称
func (Floor) FloorNameMap(ctx context.Context, floorIDs []string) map[string]string {
	idNameMap := make(map[string]string)
	f := dal.Floor
	fx := f.WithContext(ctx)
	records, err := fx.Where(f.ID.In(floorIDs...)).Find()
	if err != nil {
		return nil
	}
	for _, record := range records {
		idNameMap[record.ID] = record.Name
	}
	return idNameMap
}

// List 楼层列表
func (Floor) List(ctx context.Context, query *dal.Query, locationID string) ([]*models.Floor, int64, error) {
	f := query.Floor
	tx := f.WithContext(ctx).Where(f.LocationID.Eq(locationID))
	total, _ := tx.Count()
	if total <= 0 {
		return []*models.Floor{}, 0, nil
	}
	list, _ := tx.Find()
	return list, total, nil
}
